package com.wy.powerbuilder.controller.ld;

import com.wy.powerbuilder.util.CpachaUtil;
import com.wy.powerbuilder.util.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class CpachaServlet extends HttpServlet {

	
	private static final long serialVersionUID = 4919529414762301338L;


	@RequestMapping("CpachaServlet")
	private void getLoginCpacha(HttpServletRequest req, HttpServletResponse resp) {

		String vl= req.getParameter("vl");
		String fs = req.getParameter("fs");
		int vcodeLength = 4;
		int fontSize = 21;
		if(!StringUtil.isEmpty(vl)){
			vcodeLength = Integer.parseInt(vl);
		}
		if(!StringUtil.isEmpty(fs)){
			fontSize = Integer.parseInt(fs);
		}
		CpachaUtil cpachaUtil = new CpachaUtil(vcodeLength,fontSize);
		String generatorVCode = cpachaUtil.generatorVCode();
		//�����ɵ���֤�����session��������¼ʱ����֤
		req.getSession().setAttribute("loginCpacha", generatorVCode);
		BufferedImage generatorRotateVCodeImage = cpachaUtil.generatorRotateVCodeImage(generatorVCode, true);
		try {
			ImageIO.write(generatorRotateVCodeImage, "gif", resp.getOutputStream());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
}